/* This file includes general macros, functions, et. al
needed elsewher in the interface files. It also includes
all the need SWIG files */
%module "evolution"
%include "constraints.i"
%{
	typedef gchar must_free_g_char;
%}
/* Implements a read function for a property of a given type
for a given class */
%define PROPERTY_READ_IMP(class, property, type, function)
%{
    type class ## _ ## property ##_get( class * obj) {
            return function(obj);
    }  

%}
%enddef

/* Defines a readonly property and implements a read function 
for a it of a given type for a given class. Variant where e-d-s
allocates the var for us*/

%define PROPERTY_READ(class, property, type, function)
   %extend class {
        %immutable;
            type property;    
    }
    PROPERTY_READ_IMP(class, property, type, function)
%enddef



/* Implements a read function for a property of a given type
for a given class where eds allocs the var for us */
%define PROPERTY_EDS_ALLOC_READ_IMP(class, property, type, function)
%{
    type class ## _ ## property ##_get( class * obj) {
            type var;
            function(obj, &var);
            return var;
    }  

%}
%enddef

/* Defines a readonly property and implements a read function 
for a it of a given type for a given class */

%define PROPERTY_EDS_ALLOC_READ(class, property, type, function)
   %extend class {
        %immutable;
            type property;    
    }
    PROPERTY_EDS_ALLOC_READ_IMP(class, property, type, function)
%enddef




/* Implements a write function for a property of a given type
for a given class */

   
%define PROPERTY_WRITE_IMP(class, property, type, function)    
%{
    void class ## _ ## property ##_set( class * obj, type param) {
            function(obj, param);
    }  
%}
%enddef

/* Defines a property and implements a write function 
for a it of a given type for a given class */
   
%define PROPERTY_WRITE(class, property, type, function)    
   %extend class {
        %mutable;
            type property;    
    }
    PROPERTY_WRITE_IMP(class, property, type, function)

%enddef

/* Defines a property and implements a property for a given class */
 
%define PROPERTY_RW(class, property, type, function_read, function_write)        
    %extend class {
        type property;    
    }
    PROPERTY_READ_IMP(class, property, type, function_read)
    PROPERTY_WRITE_IMP(class, property, type, function_write)
%enddef


/* Defines a property and implements a property for a given class
e-d-s allocation variant */
 
%define PROPERTY_EDS_ALLOC_RW(class, property, type, function_read, function_write)        
    %extend class {
        type property;    
    }
    PROPERTY_EDS_ALLOC_READ_IMP(class, property, type, function_read)
    PROPERTY_WRITE_IMP(class, property, type, function_write)
%enddef






/* Implements a read function for a property of a given type
for a given class */
%define PTR_PROPERTY_READ_IMP(class, property, type, function)
%{
    type class ## _ ## property ##_get( class * obj) {
            type prop;
            function(obj, &prop);
            return prop;
    }  

%}
%enddef



/* Defines a readonly property for structs and implements a
read function for a it of a given type for a given class */

%define PTR_PROPERTY_READ(class, property, type, function)
   %extend class {
        %immutable;
            type property;    
    }
    PTR_PROPERTY_READ_IMP(class, property, type, function)
%enddef

/* Implements a write function for a property of a given type
for a given class */


   
%define PTR_PROPERTY_WRITE_IMP(class, property, type, function)    
%{
    void class ## _ ## property ##_set( class * obj, type param) {
            function(obj, &param);
    }  
%}
%enddef

/* Defines a property and implements a write function 
for a it of a given type for a given class */
   
%define PTR_PROPERTY_WRITE(class, property, type, function)    
   %extend class {
        %mutable;
            type property;    
    }
    PTR_PROPERTY_WRITE_IMP(class, property, type, function)
%enddef

/* Defines a property and implements a property for a given class */
 
%define PTR_PROPERTY_RW(class, property, type, function_read, function_write)        
    %extend class {
        type property;    
    }
    PTR_PROPERTY_READ_IMP(class, property, type, function_read)
    PTR_PROPERTY_WRITE_IMP(class, property, type, function_write)
%enddef


/* Defines a destructor for a given class */

%define DEFINE_DESTRUCTOR(class, funct)
   %extend class {
        ~ ## class () {         	
        	funct (self); 
        }
    }
%enddef

/* Default denstructor is to g_object_unref */
%define DEFINE_DEFAULT_DESTRUCTOR(class)
    DEFINE_DESTRUCTOR(class, g_object_unref)
    
%enddef



/* ITERATE over a GLIB collection of iterator_class contained in class retrieved by func_collection and apply func_obj to them */
%define ITERATE_OVER_COLLECTION(class, iterator_class, collection_class, func_collection, func_obj)
	%extend class {		
		%{
			static void class ## _iterate_ ## iterator_class ## _with_ ## func_collection ## _apply_ ## func_obj (gpointer data, gpointer user_data)
			{				
				iterator_class* obj = (iterator_class *) data;
				func_obj(obj, user_data);	        
			}
		%}
	};
%enddef

%include "esource.i"

%include "esourcegroup.i"

%include "ecalcomponentalarm.i"

%include "ecalcomponent.i"

%include "ecal.i"
typedef enum {
	E_CAL_SOURCE_TYPE_EVENT,
	E_CAL_SOURCE_TYPE_TODO,
	E_CAL_SOURCE_TYPE_JOURNAL,
	E_CAL_SOURCE_TYPE_LAST
} ECalSourceType;

typedef enum {
	E_CAL_COMPONENT_ALARM_NONE,
	E_CAL_COMPONENT_ALARM_AUDIO,
	E_CAL_COMPONENT_ALARM_DISPLAY,
	E_CAL_COMPONENT_ALARM_EMAIL,
	E_CAL_COMPONENT_ALARM_PROCEDURE,
	E_CAL_COMPONENT_ALARM_UNKNOWN
} ECalComponentAlarmAction;


/* Implement module functions */
%{
    #include <libedataserver/e-source-list.h>
    #include <libecal/e-cal.h>

    ESourceList* get_esource_groups(ECalSourceType t=E_CAL_SOURCE_TYPE_EVENT){
        ESourceList* list;
        GError* error = 0;  
        e_cal_get_sources(&list,  t, &error);
        if(!error)
            return list;
        else 
            return NULL;
    }
%}

/* Make SWIG conscious of function we want exported to the module */
ESourceList* get_esource_groups(ECalSourceType t=E_CAL_SOURCE_TYPE_EVENT);


/* This should be included when initiliazing the module */
%init %{
	g_type_init();
	#ifdef LANGUAGE_INIT_FUNCTION
	 lang_init_func();
	#endif
%}


